package com.zhazha.earlybird.dao;

import java.util.ArrayList;

import com.zhazha.earlybird.beans.UserInfo;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class ArticleDetailDAO {

	
	private SQLiteDatabase mDatabase;
	private static final String ARTICLE_TABLE = "article";
	
	private static final String ARTICLE_CATEGORY 				= "Category";
	private static final String ARTICLE_TITLE				= "Title";
	private static final String ARTICLE_CONTENT		= "content";
	
	
	public ArticleDetailDAO(SQLiteDatabase db) {
		mDatabase = db;
	}
	
	public ArrayList<String>  querybycategory()
	{
		ArrayList<String> category_list=new ArrayList<String>();
		
		try {
			
			String[] columns={ARTICLE_CATEGORY};
			Cursor c = this.mDatabase.query(true, ARTICLE_TABLE, columns,null, null, null, null, null, null);
			
			if(c.getCount()==0)
			{
				category_list=null;
			}else
			{
				if (c.moveToFirst()){
					for(int i=0;i<c.getCount();i++)
					{
						category_list.add(c.getString(c.getColumnIndex(ARTICLE_CATEGORY)));
						c.moveToNext();
					}
					
				}
			}
				
				
			
			
			return category_list;
			
		}catch (Exception e) {
			e.printStackTrace();
			return category_list;
		}
	}
	
	public ArrayList<String>	querybycategory(String Category)
	{
		
		ArrayList<String> title_list=new ArrayList<String>();
		
		try {
			
			String[] columns={ARTICLE_TITLE};
			String selection = "category=?";
			String[] selectionArgs={Category};
			Cursor c = this.mDatabase.query(ARTICLE_TABLE, columns, selection, selectionArgs, null, null, null);
			
			if(c.getCount()==0)
			{
				title_list=null;
			}else{
				
				if (c.moveToFirst()){
					for(int i=0;i<c.getCount();i++)
					{
						title_list.add(c.getString(c.getColumnIndex(ARTICLE_TITLE)));
						c.moveToNext();
					}
					
				}
			}
				
				
			
			
			return title_list;
		}catch (Exception e) {
			e.printStackTrace();
			return title_list;
		}
	}
	
	public ArrayList<String>	querybytitle(String title)
	{
		
		ArrayList<String> content_list=new ArrayList<String>();
		
		try {
			
			String[] columns={ARTICLE_CONTENT};
			String selection = "title=?";
			String[] selectionArgs={title};
			Cursor c = this.mDatabase.query(ARTICLE_TABLE, columns, selection, selectionArgs, null, null, null);
			if(c.getCount()==0)
			{
				content_list=null;
			}else
			{
				if (c.moveToFirst()){
					for(int i=0;i<c.getCount();i++)
					{
						content_list.add(c.getString(c.getColumnIndex(ARTICLE_CONTENT)));
						c.moveToNext();
					}
					
				}
			}
				
				
			
			
			return content_list;
		}catch (Exception e) {
			e.printStackTrace();
			return content_list;
		}
	}
}
